package pap.tasks;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

import pap.utils.UncompatibleDimensionsException;


public abstract class Task {

	ExecutorService executors;

	public Task(int threadNum,ThreadFactory tF) {
		executors = Executors.newFixedThreadPool(threadNum,tF);
	}

	protected abstract void mainTask() throws UncompatibleDimensionsException, InterruptedException;

	public void start() {

		executors.execute(new Runnable() {

			@Override
			public void run() {
				while (true) {
					
					try {
						mainTask();
					} catch (InterruptedException e) {
						e.printStackTrace();
					} catch (UncompatibleDimensionsException e) {
						e.printStackTrace();
					} 
				}
			}
		});
	}

}